'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('sales', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        mobile:{
            type: Sequelize.STRING(20),
        },
        carNum:{
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        cost: {
            type: Sequelize.INTEGER(8),
            defaultValue: 0,
            allowNull: false,
        },
        serviceItems: {
            type: Sequelize.JSON,
            allowNull: false,
        },
        payFlag: {
            type: Sequelize.INTEGER(2),
            allowNull: false,
        },
        payTime: {
            type: Sequelize.DATE,
        },
        checkFlag:{
            type: Sequelize.INTEGER(1),
            defaultValue: 1,
            allowNull: false,
        },
        postFlag: {
            type: Sequelize.INTEGER(2),
            defaultValue: 0,
            allowNull: false,
        },
        invoiceFlag: {
            type: Sequelize.INTEGER(1),
            allowNull: false,
        },
        licenseFlag: {
            type: Sequelize.INTEGER(1),
            allowNull: false,
        },
        alertFlag: {
            type: Sequelize.INTEGER(1),
            allowNull: false,
        },
        flag:{
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
            allowNull: false,
        },
        status:{
            type: Sequelize.INTEGER(2),
            defaultValue: 0,
            allowNull: false,
        },
        agentId:{
          type: Sequelize.STRING(100)
        }
    }, {
        freezeTableName: true,
        tableName: 'tb_sales',
        timestamps: true,
        paranoid: true,
    })

    Model.associate = function() {
        model.Sales.belongsTo(model.Corp)
        model.Sales.belongsTo(model.Client)
        model.Sales.belongsTo(model.Agent)
        model.Corp.hasMany(model.Sales)
        model.Client.hasMany(model.Sales)
        model.Agent.hasMany(model.Sales)
    }

    return Model
}